package com.example.demo.mapper;

import com.example.demo.entity.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StudentMapper {

    @Select("select * from studentinfo where name=#{name} and status = 1")
    Student selectByName(@Param("name") String name);

    @Select("select * from studentinfo where status = 1")
    List<Student> findAlllStu();

    @Select("select * from studentinfo where college=#{college} and status = 1")
    List<Student> findStuByCollege(@Param("college") String college);

    @Select("select * from studentinfo where grade=#{grade} and status = 1")
    List<Student> findStuByGrade(@Param("grade") String grade);

    @Select("select * from studentinfo where college=#{college} and grade=#{grade} and status = 1")
    List<Student> findStuByCollegeAndGrade(@Param("college") String college, @Param("grade") String grade);

    @Select("select * from studentinfo where major=#{major}")
    List<Student> findStuByMajor(@Param("major") String major);

    @Update("update from studentinfo set status = 2 where id=#{id}")
    int deleteStu(@Param("id") int id);

    @Insert("insert into studentinfo(id,name,college,major,classi,tele) values (#{id},#{name},#{college},#{major},#{classi},#{grade},#{tele})")
    int insertstu(Student stu);

    @Select("select * from studentinfo order by id desc limit 1 ")
    Student selectLast();

    @Update("update studentinfo set name=#{name},college=#{college},major=#{major},classi=#{classi},tele=#{tele} where id=#{id}")
    int updateStu(@Param("name") String name, @Param("college") String college, @Param("major") String major, @Param("classi") String classi, @Param("tele") String tele, @Param("id") int id);

    @Update("update studentinfo set grade=#{grade} where id=#{id}")
    int updateStuGrade(@Param("grade") String grade, @Param("id") int id);

    @Select("select * from studentinfo where 1=1 and id=#{id}")
    Student selectStuById(@Param("id") int id);

    @Select("<script>" +
            "SELECT * FROM studentinfo " +
            "WHERE id IN " +
            "<foreach item='id' collection='ids' open='(' separator=',' close=')'>" +
            "   #{id}" +
            "</foreach>" +
            "</script>")
    List<Student> selectStudentByIds(@Param("ids") List<Integer> ids);
}
